<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
require 'Eventageous.php';
require 'EventageousEvent.php';
//require 'Eventageous_Emergency.php';

// this is based on the sample handler provided by: http://www.php.net/manual/en/function.set-error-handler.php
function php_error_handler($errno, $errstr, $errfile, $errline)
{
	switch ($errno) 
	{
		case E_USER_ERROR:
			$str = "$errstr: Fatal error on line $errline in file $errfile";
			Eventageous::error( $str, debug_backtrace(), array($errno) );
			exit(1);
		break;
		
		case E_USER_WARNING:
			$str = "$errstr: Warning on line $errline in file $errfile";
			Eventageous::warning( $str, debug_backtrace(), array($errno) );
		break;
		
		case E_USER_NOTICE:
			$str = "$errstr: Notice on line $errline in file $errfile";
			Eventageous::info( $str, debug_backtrace(), array($errno) );
		break;
		
		default:
			$str = "$errstr: Unknown error: Line $errline in file $errfile";
			Eventageous::log( $str, debug_backtrace(), array($errno) );
		break;
	}
	
	// Don't execute PHP internal error handler
	return true;
}

function php_exception_handler($ex)
{
	Eventageous::error( $ex, debug_backtrace(), array('php exception') );
}

Eventageous::set_log('default.txt', 'logs');

//set_error_handler('php_exception_handler', E_ALL);
set_exception_handler('php_exception_handler');
function throwit() 
{
	throw new Exception('test exception');
}
//throwit();

Eventageous::log('hello world');
Eventageous::emergency('hello world');
Eventageous::alert('hello world');
Eventageous::critical('hello world');
Eventageous::error('hello world');
Eventageous::warning('hello world');
Eventageous::notice('hello world');
Eventageous::info('hello world');
Eventageous::debug('hello world');
?>

<script type="text/javascript">
var xmlHttpReq = false;
if (window.XMLHttpRequest)
	xmlHttpReq = new XMLHttpRequest();
else if (window.ActiveXObject)
	xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

xmlHttpReq.open('GET', 'ajax.php', true);
xmlHttpReq.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) 
	{
		console.log( eval(xmlHttpReq.responseText) );
	}
}
xmlHttpReq.send(null);
</script>
</body>
</html>
